package com.zhangxin.designmode.fiveprinciple.openclosedprinciple.after;

import com.zhangxin.designmode.fiveprinciple.openclosedprinciple.before.NotificationEmergencyLevel;

/**
 * @author zhangxin
 * @date 2022/4/9
 */
public class TpsAlertHandler extends AlertHandler {

    public TpsAlertHandler(AlertRule alertRule, Notification notification) {
        super(alertRule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        long tps = apiStatInfo.getRequestCount() / apiStatInfo.getDurationOfSeconds();
        if (tps > alertRule.getMatchedRule(apiStatInfo.getApi()).getMaxTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY.getInfo(), "...");
        }
    }
}
